import re
import os
import calendar

"""
# Code for Skiena Lecture files

os.chdir("D:/LOCAL/Skiena Algorithms")

for f in os.listdir(): 
    if os.path.isfile(f) and re.match(r"^\d+_\d+_\d+$", f):
        os.rename(f, f[re.search(r"\d+$",f).start():] + ".flv")
"""


# Code for CapitalOne statement files
"""
os.chdir("C:/Users/Artur/Documents/! SAVED BILLS/CapitalOne Mastercard/tmp")
months = dict((m,n) for n,m in enumerate(calendar.month_name))

for f in os.listdir(): 
    (fname, ext) =  f.split('.')
    (month, day, year) = fname.split()
    os.rename(f, "{} {:02d} {:02d}.{}".format(year, months[month], int(day), ext))
    #print("renaming \"{}\" to \"{} {:02d} {:02d}.{}\"".format(f, year, months[month], int(day), ext))
"""    

# Code for RBC statement files
#os.chdir("C:/Users/Artur/Documents/! SAVED BILLS/RBC/08000-5225016 Chequing/t")
#months = dict((m,n) for n,m in enumerate(calendar.month_abbr))
#
#for f in os.listdir(): 
#    (fname, ext) =  f.split('.')
#    if(len(fname) > 32): 
#        continue;
#    
#    (acc, start, end) = fname.split('-')
#    (s_year, s_month, s_day) = (start[:4], start[4:7], start[7:])
#    (e_year, e_month, e_day) = (end[:4], end[4:7], end[7:])
#    os.rename(f, "{} - {} {:02d} {:02d} - {} {:02d} {:02d}.{}"
#              .format(acc, s_year, months[s_month], int(s_day), e_year, months[e_month], int(e_day),  ext))
#    print("renaming \"{}\" to \"{} - {} {:02d} {:02d} - {} {:02d} {:02d}.{}\""
#          .format(f,acc, s_year, months[s_month], int(s_day), e_year, months[e_month], int(e_day),  ext)) 
#    
    
# Code for hydro statement files
#os.chdir("C:/Users/Artur/Documents/! SAVED BILLS/KW Hydro/tmp")
#monthcodes = [x.upper() for x in calendar.month_abbr]
#months = dict((m,n) for n,m in enumerate(monthcodes))
#
#for f in os.listdir(): 
#    (fname, ext) =  f.split('.')
#    (month, day, year) = fname.split()
#    os.rename(f, "{} {:02d} {:02d}.{}".format(year, months[month], int(day), ext))
#    #print("renaming \"{}\" to \"{} {:02d} {:02d}.{}\"".format(f, year, months[month], int(day), ext))


os.chdir("I:/TNG/")

for f in os.listdir(): 
    if os.path.isfile(f):
        (fname, ext) =  f.rsplit('.', 1)
        (name, title) = fname.split('-')
        t = name.split(' ')
        fname = "{}{}.{}.{}".format(t[6], t[8], title.strip(), ext)
        print(fname)
        os.rename(f, fname)
    




#os.chdir("I:/Data Science")
#
#for f in os.listdir(): 
#    (fname, ext) =  f.rsplit('.', 1)
#    
#    (sec, ep, name) = fname.split('-', 2)
#    try:
#        int(name[0:2])
#        name = name[3:]
#    except ValueError:
#        pass
#        
#    fname = "0{:0>2}{:0>2}.{}.{}".format(int(sec), int(ep), name[1:], ext)
#    print(fname)
#    os.rename(f, fname)
















